<?php
defined('IN_ADMIN') or exit('No permission resources.');
$show_validator = $show_scroll = $show_dialog = 1;
include $this->admin_tpl('header', 'admin');

?>
<h3 style="padding-left: 20px;padding-top: 10px">
	<?php echo $liveinfo['title']?>——关联用户
	<a href="?m=subject_live&c=manage&a=init" style="font-size:14px;color: #0000FF"><em>返回上一级</em></a>
</h3>

<div class="subnav">

</div>
<div class="pad-lr-10">
	<form name="searchform" action="" method="get" >
			<input type="hidden" value="<?php echo ROUTE_M;?>" name="m">
			<input type="hidden" value="<?php echo ROUTE_C;?>" name="c">
			<input type="hidden" value="<?php echo ROUTE_A;?>" name="a">
			<input type="hidden" value="1" name="search">
			<input type="hidden" value="<?=$subject_id?>" name="id">
			<input type="hidden" value="<?php echo $pc_hash;?>" name="pc_hash">
			<table width="100%" cellspacing="0" class="search-form">
				<tbody>
				<tr>
					<td>

						<button type="button" style="float:right;margin-right:20px;margin-top:10px;" onclick="showSelect()" ><em>选择用户</em></button>
						<span style="clear: both"></span>
						<script>
							function  showSelect(){
								window.top.art.dialog({
										id: 'select',
										iframe: '?m=subject_live&c=user&a=bindView&subject_id=<?=$subject_id?>',
										title: '选择用户',
										width: '900',
										height: '500',
										lock: true
									},
									function() {
										var d = window.top.art.dialog({
											id: 'select'
										}).data.iframe;
										var relation = d.document.getElementById('relation');


										if(relation.value!=""){
											$.ajax({
												type:"get",
												url:"?m=subject_live&c=user&a=bindAction&subject_id=<?=$subject_id?>&relation="+relation.value+"&pc_hash=<?php echo $_SESSION['pc_hash'];?>",
												dataType: "json",
												success:function(data){
													if(data['status']){
														window.top.art.dialog({
															id: 'select'
														}).close()
														window.location.reload();
													}else{
														alert(data['msg']);
														return false;
													}
												}
											})
										}else{
											return true;
										}

									},
									function() {
										window.top.art.dialog({
											id: 'select'
										}).close()
									});
							}
						</script>


						<div class="explain-col">
							<?php echo L('nickname');?>：<input name="nickname" type="text" value="<?php echo $_GET['nickname']?>" class="input-text" />
							<?php echo L('tel');?>：<input name="tel" type="text" value="<?php echo $_GET['tel']?>" class="input-text" />
							<input type="submit" name="search" class="button" value="<?php echo L('search');?>" />
						</div>
					</td>
				</tr>
				</tbody>
			</table>
		</form>
	
	<form name="myform" id="myform" action="?m=subject_live&c=user&a=del_all&subject_id=<?php echo $subject_id?>" method="post" onsubmit="return confirm('<?php echo L('confirm')?>')">
		<input type="hidden" value="" name="relation" id="relation">
		<div class="table-list">
			<table width="100%">
				<thead>
				<tr>
					<th align="center" width="20"><input type="checkbox" value="" id="check_box" onclick="selectalls('uid[]');selectall('id[]')"></th>
					<th width="30">ID</th>
					<th width="30"><?php echo L('nickname');?></th>
					<th width="60"><?php echo L('photo_url')?></th>
					<th width="60"><?php echo L('gender')?></th>
					<th width="120"><?php echo L('birthday');?></th>
					<th width="120"><?php echo L('tel');?></th>
					<th width="100"><?php echo L('bind_time');?></th>
					<th width="100"><?php echo L('bind_by');?></th>
					<th width="100"><?php echo L('operation');?></th>
				</tr>
				</thead>
				<tbody id="select_id">
				<?php
				if(!empty($info)){
					if(is_array($info)) {
	
						foreach ($info as $k=> $r) {
							?>
							<tr>
								<td align="center"onclick="select_list(this,<?php echo $r['id'];?>)" class="cu" style="cursor: default;"><input type="checkbox" value="<?php echo $r['sid']?>" name="id[]"></td>
								<td align="center" style="display:none;"><input type="checkbox" class="inputcheckbox" value="<?php echo $r['id']?>" name="uid[]"></td>
								<td align="center"><?php echo $r['sid']?></td>
								<td align='center'><?php echo $r['nickname']?></td>
								<td align='center'><?php if(!empty($r['photo_url'])){?><img src="<?php echo $r['photo_url'];?>" height="60"/><?php }else{echo"<span style='color:red;'>（未设置）</span>";}?></td>
								<td align='center'><?php if($r['gender'] == '1'){echo '男';}elseif($r['gender'] == '2'){echo '女';}elseif($r['gender'] == '3'){echo '保密';}?></td>
								<td align='center'><?php if(!empty($r['birthday'])){echo $r['birthday'];}else{echo "<font color='red'>未设置</font>";}?></td>
								<td align='center'><?php if(!empty($r['tel'])){echo $r['tel'];}else{echo "<font color='red'>未设置</font>";}?></td>
								<td align='center'><?php echo $r['screate_time'];?></td>
								<td align='center'><?php echo $adminInfo[$r['created_by']];?></td>
								<td align='center'>
									<a href="?m=subject_live&c=user&a=del&id=<?php echo $r['sid']?>&subject_id=<?php echo $subject_id;?>&uid=<?php echo $r['id']?>" onClick="return confirm('<?php echo L('confirm')?>')"><?php echo  L("del");?></a>
								</td>
	
							</tr>
						<?php }
					}
				}else{
				?>
					<tr><td colspan='8' style='color:red;font-size:18px;text-align:center;'><span>暂无数据！</span></td></tr>
				<?php }?>
				</tbody>
			</table>
			<div class="btn">
				<label for="check_box"><a href="#"
					onClick="javascript:$('input[type=checkbox]').attr('checked', true)"><?php echo L('select_all')?></a>/
					<a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', false)"><?php echo L('cancel')?></a>
				</label>
				<input type="submit" class="button" name="dosubmit" value="<?php echo L('delete')?>" />
			</div>
			<div id="pages"><?php echo $pages;?></div>
		</div>
	</form>
</div>
<script type="text/javascript">
<!--
function selectalls(name) {
	//alert($('#select_id tr .inputcheckbox').length);
	var objs = $('#select_id tr .inputcheckbox');
	var strs = '';
	if ($("#check_box").attr("checked")=='checked') {
		$("input[name='"+name+"']").each(function() {
  			$(this).attr("checked","checked");
  			
			$('#select_id tr').attr('class','line_ff9966');
		});
		for(var i=0; i<objs.length; i++){
			if (i == 0) {
				if(objs[i].checked) strs = objs[i].value;
			} else {
				if(objs[i].checked) strs +='|' + objs[i].value;
			}
		}
		$('#relation').val(strs);
	} else {
		$("input[name='"+name+"']").each(function() {
  			$(this).removeAttr("checked");
  			$('#select_id tr').attr('class','line_fbffe4')
  			$('#relation').val('');
		});
	}
}

function select_list(obj,id) {
	var relation_ids =$('#relation').val();
	if($(obj).attr('class')=='line_ff9966' || $(obj).attr('class')==null) {
		$(obj).attr('class','line_fbffe4');
		$(obj).find('.inputcheckbox').removeAttr("checked");
		if(relation_ids !='' ) {
			var r_arr = relation_ids.split('|');
			var newrelation_ids = '';
			$.each(r_arr, function(i, n){
				if(n!=id) {
					if(i==0) {
						newrelation_ids = n;
					} else {
					 newrelation_ids = newrelation_ids+'|'+n;
					}
				}
			});
			$('#relation').val(newrelation_ids);
		}
	} else {
		$(obj).attr('class','line_ff9966');
		$(obj).find('.inputcheckbox').attr("checked","checked");
		if(relation_ids =='' ) {
			$('#relation').val(id);
		} else {
			relation_ids = relation_ids+'|'+id;
			$('#relation').val(relation_ids);
		}
	}
}
//-->
</script>
</body>
</html>